package com.dukun.mybatis.convert;

import com.dukun.mybatis.enums.ExternalOrderType;
import com.dukun.mybatis.enums.OrderType;
import org.mapstruct.EnumMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ValueMapping;
import org.mapstruct.factory.Mappers;

/**
 * @author dukun
 * date：2021/11/30
 */
@Mapper
public interface EnumConvert {

    EnumConvert INSTANCE = Mappers.getMapper(EnumConvert.class);

    /**
     * OrderType ---> ExternalOrderType
     *
     * @param orderType OrderType
     * @return ExternalOrderType
     */
    ExternalOrderType orderTypeToExternalOrderType(OrderType orderType);

    /**
     * ExternalOrderType ---> OrderType
     * <pre>
     *     如果枚举类中没有对应的常量，可以使用MappingConstants.NULL来替代
     * </pre>
     *
     * @param externalOrderType ExternalOrderType
     * @return OrderType
     */
    @ValueMapping(source = "SITE", target = MappingConstants.NULL)
    OrderType externalOrderTypeToOrderType(ExternalOrderType externalOrderType);

    /**
     * String ---> OrderType
     *
     * @param constant String
     * @return Enum
     */
    OrderType stringToOrderType(String constant);

    /**
     * OrderType ---> String
     *
     * @param orderType OrderType
     * @return String
     */
    String orderTypeToString(OrderType orderType);
}
